define(["jquery", "easy-admin"], function ($, ea) {
    let form = layui.form;
    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'news.lists/index',
        add_url: 'news.lists/add',
        edit_url: 'news.lists/edit',
        delete_url: 'news.lists/delete',
        export_url: 'news.lists/export',
        modify_url: 'news.lists/modify',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: 'ID'},
                    {field: 'sort', title: '排序',width:100,edit:'text'},
                    {field: 'title', title: '标题'},
                    {field: 'thumb_title', title: '副标题'},
                    {field: 'type', search: 'select', selectList: {"1":"标题","2":"左右","3":"无图","4":"大图","5":"多图"}, title: '显示样式'},
                    {field: 'logo', title: '单图', templet: ea.table.image},
                    {field: 'status', search: 'select', selectList: ["禁用","启用"], title: '状态', templet: ea.table.switch},
                    {field: 'create_time', title: '创建时间'},
                    {width: 250, title: '操作', templet: ea.table.tool},
                ]],
            });

            ea.listen();
        },
        add: function () {
            form.on('radio(selectType)',function (res) {
                if(res.value == 1){
                    $("#allImage").slideDown();
                    $("#oneImage").slideUp();
                }else if (res.value == 3){
                    $("#oneImage").slideUp();
                }else{
                    $("#allImage").slideUp();
                    $("#oneImage").slideDown();
                }
            })
            ea.listen();
        },
        edit: function () {
            form.on('radio(selectType)',function (res) {
                if(res.value == 1){
                    $("#allImage").slideDown();
                    $("#oneImage").slideUp();
                }else if (res.value == 3){
                    $("#oneImage").slideUp();
                }else{
                    $("#allImage").slideUp();
                    $("#oneImage").slideDown();
                }
            })
            ea.listen();
        },
    };
    return Controller;
});